<template>
	<el-dialog :visible.sync="visible" :modal-append-to-body="false" :title="keyLan['name']" class="demo-ruleForm"
		width="70%">
		<el-form ref="formModel" :model="model" :rules="rules" :label-width="labelWidth" :inline="inline">
			<!-- <h4 class="orange">基础信息</h4> -->
			<el-row>
				<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
					<el-form-item prop="EnumSysCustomerType" :label="keyLan['EnumSysCustomerType']+':'">
						<el-radio-group v-model="model.EnumSysCustomerType">
							<el-radio v-for="item in EnumSysCustomerType" :key="item.Value" :value="item.Value"
								:label="item.Value">
								{{enumLanTxt(item.Label)}}
							</el-radio>
						</el-radio-group>
					</el-form-item>

					<el-form-item prop="SysCustomerName" :label="keyLan['SysCustomerName']+':'">
						<el-input v-model="model.SysCustomerName"></el-input>
					</el-form-item>
				</el-col>

				<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
					<el-form-item prop="HeaderUrl" :label="keyLan['HeaderUrl']+':'">
						<uploadimg v-model="model.HeaderUrl" :max="1"></uploadimg>
					</el-form-item>
				</el-col>

				<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
					<el-form-item prop="Phone" :label="keyLan['Phone']+':'">
						<el-input v-model="model.Phone"></el-input>
					</el-form-item>
				</el-col>

				<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
					<el-form-item prop="EnumStatus" :label="keyLan['EnumStatus']+':'">
						<el-radio-group v-model="model.EnumStatus">
							<el-radio v-for="item in EnumStatus" :key="item.Value" :value="item.Value"
								:label="item.Value">
								{{enumLanTxt(item.Label)}}
							</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
					<el-form-item prop="Remark" :label="keyLan['Remark']+':'">
						<el-input type="textarea" :rows="2" v-model="model.Remark" style="width: 100%;"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>

		<div slot="footer" class="dialog-footer">
			<el-button v-if="isAdd" @click="resetThisVal('model')">{{comLan["btnReset"]}}</el-button>
			<el-button @click="close">{{comLan["btnCancel"]}}</el-button>
			<el-button type="primary" @click="save" :loading="loading">{{comLan["btnSave"]}}</el-button>
		</div>
	</el-dialog>
</template>

<script>
	import common from "@/common/common.js";
	import js from "./js.js";

	export default {
		name: "SysCustomerAdd",
		components: {},
		props: {
			value: {
				type: Object,
				default: function() {
					return {};
				}
			}
		},
		mixins: [common.baseVM, js],
		data() {
			return {
				model: {
					SysCustomerID: 0,
					// SysStoreID: null,
					EnumSysCustomerType: 0,
					SysCustomerName: null,
					Phone: null,
					CreateDate: [],
					EnumStatus: 1,
				}
			}
		},
		methods: {
			init() {},

			show(scope) {
				this.loadBeforeValSuccess = false;
				this.resetVal("model");
				this.isAdd = scope == null || scope.row == null;
				if (this.isAdd) { //新建
					this.loadBeforeVal();
					this.visible = true;
					return;
				}
				var id = scope.row.SysCustomerID;
				this.get("api/Customer/SysCustomerAdd?id=" + id).then(data => {
					this.model = data.Result;
					this.visible = true;
				});
			},
			close() {
				this.visible = false;
			},
			save() {
				this.formValidate('formModel', () => {
					var post = JSON.parse(JSON.stringify(this.model));
					this.loading = true;
					this.post('api/Customer/SysCustomerAdd', post).then(data => {
						this.showToast(data.Message, "success");
						this.loading = false;

						this.clearBeforeVal();
						this.close();

						this.$emit("success");

						if (this.isAdd && !!this.$listeners["input"]) {
							this.$emit("input", data.Result);
						}
					}).catch((error) => {
						this.loading = false;
					});
				});
			}
		}
	}
</script>
